//index.js
//获取应用实例
var cfg = require('../../utils/cfg');
var util = require('../../utils/util');
const app = getApp();
const { $Toast } = require('../../dist/base/index');
var common = require('../../utils/common');
var sendRequest = require('../../utils/requestUtils');

Page({
  data: {
    merchant: {},
    sku : {}
  },
  onLoad: function () {
    let that = this;
    that.loadSku();
  },

  loadSku: function () {
    let that = this;
    sendRequest.sendReq(cfg.djurl.listSku, {
      openId: 'xxx',
      skuType : 5
    }, function (result) {
      if (result.data.length == 0) {
        return;
      }
      that.setData({
        sku: result.data[0]
      });
    });
  },

  //保存店铺信息
  saveSku: function () {
    let that = this;
    if (that.data.sku.skuName == '' || that.data.sku.skuName == undefined) {
      util.alert('请输入主营菜品');
      return;
    }

    that.data.sku.skuType = 5;

    sendRequest.sendReq(cfg.djurl.saveSku, {
      'skuInfo': JSON.stringify(that.data.sku),
      'openId': 'xxx',
      'delFirst' : true
    }, function (result) {
      console.log('修改成功');
      wx.reLaunch({
        url: '/pages/home/home'
      })
    });

  },

  zhuyingChange: function (event) {
    this.data.sku.skuName = event.detail.detail.value;
  }

})
